// 数据库配置 - 使用内存数据库作为替代
let db = {
  users: [
    // 默认测试账号
    {
      id: 1,
      username: 'admin',
      // 密码: password (已加密)
      password: '$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW',
      createdAt: new Date().toISOString()
    }
  ]
};

// 数据库操作函数
const database = {
  // 获取用户列表
  getUsers: () => db.users,
  
  // 根据用户名查找用户
  findUserByUsername: (username) => {
    return db.users.find(user => user.username === username);
  },
  
  // 添加新用户
  addUser: (user) => {
    const newUser = {
      id: Date.now(),
      ...user,
      createdAt: new Date().toISOString()
    };
    db.users.push(newUser);
    return newUser;
  },
  
  // 重置数据库（用于测试）
  reset: () => {
    db = {
      users: [
        {
          id: 1,
          username: 'admin',
          password: '$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW',
          createdAt: new Date().toISOString()
        }
      ]
    };
  }
};

export default database;